package mo.leetcode_top;

import java.util.Arrays;

public class L238 {

    public int[] productExceptSelf(int[] nums) {
        int[] res = new int[nums.length];
        //O(1)
        int right = 1;
        res[0] = 1;
        for (int i = 1; i < nums.length; i++) {
            res[i] = res[i-1] * nums[i-1];
        }

        for (int i = nums.length - 1; i >= 0; i--) {
            res[i] = res[i] * right;
            right = right * nums[i];
        }

        return res;
    }

    public static void main(String[] args) {
        L238 test = new L238();
        System.out.println(Arrays.toString(test.productExceptSelf(new int[]{-1,1,0,-3,3})));
    }

}
